home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14111 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character string
  5. Date: Thu, 11 Apr 96 14:45:13 GMT
  6. Organization: none
  7. Message-ID: <829233913snz@genesis.demon.co.uk>
  8. References: <4kil74$8i7@Tandem1.opennet.net.au>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4kil74$8i7@Tandem1.opennet.net.au>
  15.            george@opennet.net.au "Kenneth H Smith" writes:
  16.  
  17. >How do I do a similar statement in C to the Pascal code:
  18. >
  19. >If Ch IN ['a','A'] THEN
  20. >
  21. >I want to execute a piece of code when a particular character is entered
  22. >from the keyboard.
  23. >
  24. >I know I can use if (ch=='a') && (ch=='A') but was looking for something
  25. >a little more ellegant.
  26.  
  27. There is no direct equivalent although you could use a switch statement
  28. e.g.
  29.  
  30.     switch (ch) {
  31.     case 'a':
  32.     case 'A':
  33.         /* Do something */
  34.         break;
  35.     default:
  36.         /* Do something else */
  37.         break;
  38.     }
  39.  
  40. This looks clumsy for a small number of cases but is quite effective for
  41. a larger number where you would probably put more than one case per line.
  42.  
  43. For your 2 value example above you won't do much better than the if
  44. statement.
  45.  
  46. -- 
  47. -----------------------------------------
  48. Lawrence Kirby | fred@genesis.demon.co.uk
  49. Wilts, England | 70734.126@compuserve.com
  50. -----------------------------------------
  51.